package com.naizhuai.ui.components.listener;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;

import com.naizhuai.R;
import com.naizhuai.ui.components.SpinerPopWindow;
import com.naizhuai.util.NaizhuAILog;

/**
 * 显示PopupWindow
 * Created by code_han on 2018/3/27.
 */

public class SpinnerListener<T> implements View.OnClickListener {
    private SpinerPopWindow<T> mSpinerPopWindow;
    private int resourceUp;
    private Context mContext;

    public SpinnerListener(SpinerPopWindow<T> mSpinerPopWindow, int resourceUp,Context mContext) {
        this.mSpinerPopWindow = mSpinerPopWindow;
        this.resourceUp = resourceUp;
        this.mContext=mContext;
    }

    @Override
    public void onClick(View v) {
        mSpinerPopWindow.setWidth(v.getWidth());
        mSpinerPopWindow.showAsDropDown(v);
        setTextImage((TextView) v, resourceUp);
//        switch (v.getId()) {
//            case R.id.spinner_chose_company:
//                mSpinerPopWindow.setWidth(v.getWidth());
//                mSpinerPopWindow.showAsDropDown(v);
//                setTextImage((TextView) v, resourceUp);
//                break;
//            case R.id.chose_unit:
//                mSpinerPopWindow.setWidth(v.getWidth());
//                mSpinerPopWindow.showAsDropDown(v);
//                NaizhuAILog.e("sfdasdfnasl=========asdfmasdfkmaf");
//                setTextImage((TextView) v, resourceUp);
//        }
    }

    /**
     * 给TextView右边设置图片
     *
     * @param resId
     */
    private void setTextImage(TextView textView, int resId) {
        Drawable drawable = mContext.getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());// 必须设置图片大小，否则不显示
        textView.setCompoundDrawables(null, null, drawable, null);
    }
}
